package com.kg.sdk;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

import com.kg.sdk.util.KPNetworkData;
import com.kg.sdk.view.KPFloatView;
//com.kg.sdk.KPSDKGameMenuServer
public class KPSDKGameMenuServer extends Service {
    private KPFloatView kpFloatView;
    private FloatBroadReceiver mFloatBroadReceiver;
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        mFloatBroadReceiver = new FloatBroadReceiver();
        kpFloatView = new KPFloatView(this);
        mFloatBroadReceiver.registBroadcastReceiver();
        kpFloatView.showFloatView();
    }

    public void onDestroy(){
        super.onDestroy();
        kpFloatView.removFloatView();
        mFloatBroadReceiver.unregistBroadcastReceiver();
    }

    public class FloatBroadReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if(action.equals(KPNetworkData.SHOW_FLOAT_VIEW)){
                kpFloatView.showFloatView();
            }else if(action.equals(KPNetworkData.HIDE_FLOAT_VIEW)){
                kpFloatView.removFloatView();
            }
        }

        public void registBroadcastReceiver(){
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(KPNetworkData.SHOW_FLOAT_VIEW);
            intentFilter.addAction(KPNetworkData.HIDE_FLOAT_VIEW);
            registerReceiver(this,intentFilter);
        }

        public void unregistBroadcastReceiver(){
            unregisterReceiver(this);
        }
    }
}
